<div id="list_data"></div>
<script>
    $(function () {
        var menu_id = "{{$menu_id}}";

        $('#list_data').datagrid({
            rownumbers: true,
            singleSelect: true,
            pagination: false,
            fit: true,
            url: '/sys/menu/getMenuDatalist?menu_id='+menu_id,
            queryParams: {
                _token: $('meta[name="csrf-token"]').attr('content'),
                curr_menu_id: $('meta[name="curr_menu_id"]').attr('content')
            },
            columns: [[
                {title: 'id', field: 'id', hidden: true},
                {title: '数据权限名称', field: 'name', width: 100},
                {title: 'rule', field: 'rule', width: 380},
                {title: '是否生效', field: 'is_active', width: 100,formatter:function(value,row,index){
                    if(value=='1'){
                        return '生效'
                    }else{
                        return '无效'
                    }
                }},
            ]],
            onLoadSuccess: function (data) {
                if (data === null || data.total === 0) {
                    var body = $(this).data().datagrid.dc.body2;
                    body.find('table tbody').append('<tr><td colspan="3" align="center" style="padding: 10px 0"><span>暂无数据</span></td></tr>');
                }
            },
            onClickRow:function (index, row) {
                $('#form_dialog').dialog({
                    title: '编辑菜单数据',
                    width: 500,
                    height: 300,
                    left:1200,
                    closed: false,
                    cache: false,
                    draggable:false,
                    href: '/sys/menu/editMenuRule?menu_id='+menu_id+'&id='+row.id,
                    modal: true,
                    buttons: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                },
                                url: '/sys/menu/saveMenuRule',
                                type: 'post',
                                data: $('#info-form').serialize(),
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code == 200) {
                                        $('#list_data').datagrid("reload")
                                        $('#form_dialog').dialog('close');
                                    } else {
                                        $.messager.alert("提示信息", data.data, "error");
                                    }
                                }
                            });
                        }
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#form_dialog').dialog('close');
                        }
                    }]
                });
            }
        });

    });
</script>

